package com.gimi.cloud.bbp.dao.dao.product;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.gimi.cloud.bbp.dto.product.ProductSkuDto;
import com.gimi.cloud.bbp.entity.product.ProductSkuEntity;

public interface ProductSkuDao extends BaseMapper<ProductSkuEntity> {
	
    int deleteByPrimaryKey(String skuId);

    int insert(ProductSkuEntity record);

    int insertSelective(ProductSkuEntity record);
    
    int insertSelectiveDto(ProductSkuDto record);

    ProductSkuEntity selectByPrimaryKey(String skuId);
    
    List<ProductSkuDto> selectByProdId(String prodId);

    int updateByPrimaryKeySelective(ProductSkuEntity record);

    int updateByPrimaryKey(ProductSkuEntity record);
    
    @Select("SELECT prod_status FROM ec_prod_status WHERE prod_id = #{prodId}")
	int getStatusById(@Param(value = "prodId") String prodId);

    /**
     * 查询上加单品的品类模板值id
     * @return
     */
    @Select("SELECT GROUP_CONCAT(eps.sku_value) FROM (select distinct sku_value from ec_prod_sku) eps")
    String selectModelValueInProduct();

    @Select("SELECT * FROM ec_prod_sku WHERE prod_id = #{prodId} ")//AND sku_stock > 0
    List<ProductSkuDto> selectByProdIdAndStock(String prodId);
    
    //查询单品的最小库存
    @Select("SELECT SUM(sku_stock) FROM ec_prod_sku WHERE prod_id = #{prodId}")
    int findSumStockByProd(String prodId);
    
}